<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="studentList">
      <el-table-column label="班级名称" align="center" prop="className" />
      <el-table-column label="班级编码" align="center" prop="classCode" />
      <el-table-column label="电子班牌设备ID" align="center" prop="deviceId" />
      <el-table-column label="激活时间" align="center" prop="bindTime" />
      <el-table-column label="解绑时间" align="center" prop="unBindTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-circle-close"
            :disabled="!scope.row.classCode||!scope.row.deviceId"
            @click="handleDelete(scope.row)"

          >解绑</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { banPaiBindList,banPaiunBindCode } from "@/api/base/banpai.js";
import { getToken } from "@/utils/auth";

export default {
  name: "Student",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 学生表格数据
      studentList: [],
     
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      this.queryParams.schoolCode = this.$store.getters.schoolCode
      banPaiBindList(this.queryParams).then(response => {
        this.studentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    banPaiunBindList(row){
      const params = {
        classCode: row.classCode,
        deviceId: row.deviceId
      }
      banPaiunBindCode(params).then(response => {
        // console.log('response',response);
        if(response.code == 0){
          this.$message.success('解绑成功')
          this.getList()
        }
      });
    },
    /** 解绑按钮操作 */
    handleDelete(row) {
      this.$confirm('是否确认解绑该班牌设备?', {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(()=> {
        this.banPaiunBindList(row)
      }).catch(() => {
       this.$message({
            type: "info",
            message: "已取消解绑",
        });
      })
    },
  }
};
</script>
